<html>
<head>
    <meta charset="UTF-8">
    <link href="../static/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="../static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
    <link href="../static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
    <script src="../static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../js/common.js" type="text/javascript"></script>
</head>

<body class="login">
<div class="content">
    <h3 class="form-title">登录</h3>
    <div class="form-group">
        <label class="control-label">用户名</label>
        <div>
            <input class="form-control" type="text" name="userName" id="userName"/>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label">密码</label>
        <div>
            <input class="form-control" type="password" name="password" id="password"/>
        </div>
    </div>

    <div class="form-actions">
        <button class="btn blue" id="login_submit" type="submit">
            登录
        </button>
    </div>
</div>


</body>


<script>
    jQuery(document).ready(function () {
        //绑定otp的click时间用于向后端发送获取手机验证码的请求
        $("#login_submit").on("click", function () {
            var userName = $("#userName").val();
            if (userName == null || userName == ""){
                alert("用户名不能为空");
                return false;
            }

            var password = $("#password").val();
            if (password == null || password == ""){
                alert("密码不能为空");
                return false;
            }

            $.ajax({
                type: "POST",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                url: "http://"+g_host+"/user/login",
                data: JSON.stringify({ "userName": userName, "password": password}),
                xhrFields: {withCredentials: true},
                success: function (data) {
                    if (data.code == "1001") {
                        alert("登录成功");
                        set(common_localstorage_key, data.data);
                        window.location.href = "activity_list.html";
                    } else {
                        alert("登录失败：" + data.data);
                    }
                },
                error: function (data) {
                    alert("登录失败：" + data.data);
                }
            });
            return false;
        });
    });

</script>


</html>